module diansha {
	export class progressbar extends eui.Component implements eui.UIComponent {
		private di: eui.Image;
		private tap: eui.Image;
		private value: eui.Label;
		private max: eui.Label;
		private valueshuzi: diansha.shuzi;
		private maxshuzi: diansha.shuzi;
		private dangqiannum: diansha.shuzi = new diansha.shuzi(0, "n");
		private premax: diansha.shuzi
		public constructor() {
			super();
			this.skinName = "pro"

		}



		protected childrenCreated(): void {
			super.childrenCreated();

		}
		/**
		 * 刷新进度条
		 */
		public f5() {
			let s = this.premax.chu(this.maxshuzi);//数字比率
			let width = shuzi_factory.getinstance().get(this.di.width, "n");
			this.tap.width = width.cheng(s).num;
		}
		/**
		 * 获取现在应该增长的长度
		 */
		private getnowyinggaiwidth(shuzi: diansha.shuzi): number {
			this.valueshuzi = shuzi;
			let s = this.valueshuzi.chu(this.maxshuzi);//数字比率

			let width = shuzi_factory.getinstance().get(this.di.width, "n");
			return width.cheng(s).num;
		}


		/**
		 * tap宽度变长
		 */
		private tapwidthbianchang(n: number) {
			if (this.tap.width + n > this.di.width) {
				this.tap.width = this.di.width
			} else {
				this.tap.width = this.tap.width + n

			}

		}

		/**
		 * 	当前数字变大
		 */
		private shuzidangqianbianda(shuzi: diansha.shuzi) {
			let nows = this.dangqiannum.add(shuzi)
			if (nows.dayudengyu(this.maxshuzi)) {
				nows = this.maxshuzi;
				this.can_tupo();
				this.premax = this.maxshuzi;
			}
			if (nows.danwei != "n") {
				this.value.text = nows.num.toFixed(3) + nows.danwei;
			} else {
				this.value.text = nows.num + "";
			}
			this.dangqiannum = nows;

		}

		private can_tupo() {
			cores.getinstatic().main.tupo.enabled = true;
		}
		public setvalue(shuzi: diansha.shuzi) {
			let n = this.getnowyinggaiwidth(shuzi);
			this.shuzidangqianbianda(shuzi);
			this.tapwidthbianchang(n);

		}
		public setmax(shuzi: diansha.shuzi) {
			this.maxshuzi = shuzi;
			if (shuzi.danwei != "n") {
				this.max.text = shuzi.num + shuzi.danwei;
			} else {
				this.max.text = shuzi.num + "";
			}
		}
	}
}